package com.wondersgroup.fjzlpt.org.controller.rest.jgqy.qysq;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.quick.framework.util.ExcelOrWordUtils;
import com.wondersgroup.fjzlpt.org.util.ControllerCommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.qysq.QysqDAO;
import com.wondersgroup.fjzlpt.org.dao.inter.ksxx.KsxxDAO;
import com.wondersgroup.fjzlpt.org.dao.inter.yljgxx.YljgxxDAO;
import com.wondersgroup.fjzlpt.org.service.inter.jgqy.qysq.QysqService;

@RestController
@RequestMapping("qysq")
public class QysqRestController {
	
	@Autowired
	private QysqService qysqService;

	@Autowired
	private YljgxxDAO yljgxxDAO;
	
	@Autowired
	private QysqDAO qysqDAO;
	
	@Autowired
	private KsxxDAO ksxxDAO;
	
	
	@RequestMapping("/queryPage")
	public JSONObject queryPageYljgxx(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		ControllerCommonUtil.pageFormat(map);
		return qysqService.queryPage(map);
	}
	
	@RequestMapping("/save")
	public JSONObject save(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return qysqService.save(map);
	}
	
	@RequestMapping("/export")
	public void export(HttpServletRequest request,HttpServletResponse response)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		JSONArray jsarry = qysqService.queryList(map);
		List<String> titleField = new ArrayList<String>();
		titleField.add("YLTMC");
		titleField.add("ZDYLJGMC");
		titleField.add("YLJGMC");
		titleField.add("YLTLXMC");
		titleField.add("QYSJ");
		titleField.add("QYYXQMC");
		titleField.add("QYZT");
		ExcelOrWordUtils.downLoadExcelFile(jsarry, titleField, "签约申请", request, response);
	}
	
	@RequestMapping("/queryYljgAndKs")
	public JSONArray queryYljgAndKs(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return qysqService.queryYljgAndKs(map);
	}
	
	/*@RequestMapping("/queryYlt")
	public JSONObject queryYlt(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		JSONObject res = new JSONObject();
		if(map.containsKey("YLTID")){
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			res.put("qysqxx", jo);
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			res.put("qyjgxx", ja);
			map.put("YLJGID", jo.getString("ZDYLJGID"));
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			res.put("fqyljgxx", json.get("rows"));
		}
		return res;
	}
	
	@RequestMapping("/queryYltlb")
	public JSONObject queryYltlb(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		UtilPageFormat.pageFormat(map);
		JSONObject jo = qysqDAO.queryYltxx(map);
		return jo;
	}*/
	
	@RequestMapping("/queryKslb")
	public JSONObject queryKslb(HttpServletRequest request)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		ControllerCommonUtil.pageFormat(map);
		JSONObject jo = ksxxDAO.queryPage(map);
		return jo;
	}
}
